package activity.personal.qianbao;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.hutoubenjg.R;

import java.util.Observable;
import java.util.Observer;

import base.BaseActivity;
import base.MyApplcation;
import presenter.SysTemPresenter;
import presenter.UserPresenter;
import util.utls.ByAlert;
import util.utls.Const;
import util.utls.IsUtilUid;
import util.utls.SPUtils;
import util.volley.ResultEntity;


/**
 * 添加银行卡3
 */
public class AddBankCardThreeActivity extends BaseActivity implements Observer {
    TextView tvTitle;
    ImageView back;
    EditText add_bank03_code;
    TextView add_bank03_ok;
    SysTemPresenter presenter;
    String names, model;
    String xingming;
    UserPresenter userPresenter;
    String yhk_type;
    String phone;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_bank_card_three);
        tvTitle.setText("账户绑定");

        presenter = new SysTemPresenter(this);

        names = getIntent().getStringExtra("name");
        xingming= getIntent().getStringExtra("xingming");
        yhk_type = getIntent().getStringExtra("yhk_type");
        phone = getIntent().getStringExtra("phone");
        userPresenter = new UserPresenter(this);
        presenter.onBangDinType();
        model = (String) SPUtils.get(MyApplcation.ctx, null, Const.MOBILE, "");


    }

    @Override
    protected void onInit() {

    }

    @Override
    protected void onReadIntent(Bundle bundle) {

    }

    @Override
    public void onClick(View v) {
        Intent intent = null;
        switch (v.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.add_bank03_ok:

                if (add_bank03_code.getText().toString() == null || add_bank03_code.getText().toString().equals("")) {
                    ByAlert.alert("请填写验证码");
                } else {

                    userPresenter.YanZhengverificationCode("+86", model, add_bank03_code.getText().toString(), 2 + "");
                    showProgressDialog("加载中...", true);

                    Log.d("werwerwertwetwaet", names);
                }
                break;
            default:
                break;
        }
    }

    @Override
    public void update(Observable observable, Object data) {
        ResultEntity entity = handlerError(data);
        if (entity != null) {
            IsUtilUid.tianjia(entity);
            if (entity.getEventType() == presenter.BANG_success) {
                ByAlert.alert(entity.getData());
                this.finish();
            }
            if (entity.getEventType() == UserPresenter.yanzheng_code_success) {
//                ByAlert.alert(entity.getData());
                presenter.onByWalletBind(IsUtilUid.isUid(), names, "6197", yhk_type,xingming);

            }
            if (entity.getEventType() == UserPresenter.yanzheng_code_fail) {
                ByAlert.alert(entity.getData());
            }
        }
        try {
            closeProgressDialog();
        } catch (Exception Exception) {
        }
    }

}
